import axios from "axios"
import router from "../router"
import elementUi from "element-ui"
 let http = axios.create({
    baseURL:"/api",
    withwithCredentials: true,
    timeout:1000*10
})

http.interceptors.request.use(function(config){
    let rowPaths = ["/users/login","/users/getCaptcha","/users/verifyCaptcha"]
    if(rowPaths.includes(config.url)){
        return config
    }else{
        let token = localStorage.getItem("qf-token") || " "
        config.headers["authorization"] = token;
        return config
    }
})

http.interceptors.response.use(function(config){
    if(config.data.code === "10022" || config.data.code === "1004"){
        localStorage.removeItem("qf-token")
        location.reload()
        router.push("/login")
        elementUi.Message.error("登入过期")
    }
    return config
})

export default http;